/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Structures;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Krit
 */
public class Entry {

    public String name;
    public float price;
    public float quantity;
    public String category;
    public String shop = "";    //to poprawic, bo chamskie jest
    public Date date;
    public static final SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");

    public Entry() {
    }
    
    public Entry(String s, String c) {
        String[] entry = s.split(" ");
        this.name = entry[0];
        this.price = Float.parseFloat(entry[1]);

        if (entry.length == 3) {
            this.quantity = Integer.parseInt(entry[2]);
        } else {
            this.quantity = 1;
        }

        this.category = c;
        date = new Date();

    }
    
    public Entry(String s, String c, String shop) {
        String[] entry = s.split(" ");
        this.name = entry[0];
        this.price = Float.parseFloat(entry[1]);

        if (entry.length == 3) {
            this.quantity = Integer.parseInt(entry[2]);
        } else {
            this.quantity = 1;
        }

        this.category = c;
        this.shop = shop;
        date = new Date();

    }

    public String getString() {
        String s = new String();

        s += name + ", za: " + price + "zl, ";
        if (quantity != 1) {
            s += " " + quantity + " sztuk, ";
        }
        
        if(!shop.isEmpty()) {
            s += " " + shop;
        }

        s += " " + sdf.format(date);
        s += " " + category;

        return s;
    }
}